class TestObj:
    def __init__(self, name, age):
        self.name = name
        self.age = age

    def test(self):
        print("执行test方法")


def a():
    print("类外部方法")


if __name__ == '__main__':

    xiaoyu = TestObj('小宇', 18)

    print(getattr(xiaoyu, "name"))
    # getattr(xiaoyu, 'test')()
    #
    # print(hasattr(xiaoyu, 'name'))
    # print(hasattr(xiaoyu, 'test'))
    #
    # delattr(xiaoyu, 'name')
    # # print(getattr(xiaoyu, 'name'))
    #
    # setattr(xiaoyu, 'name', '小刚')
    # print(getattr(xiaoyu, 'name'))

    getattr(xiaoyu, 'test')()
    setattr(xiaoyu, 'test', a)
    getattr(xiaoyu, 'test')()

    print(xiaoyu.name)
    del xiaoyu.name
    setattr(xiaoyu, 'name', '小刚')
    # xiaoyu.name = '小刚'
    print(xiaoyu.name)


    # print(getattr(xiaoyu, "name"))  # 获取对象属性/对象方法
    # getattr(xiaoyu, "test")()  # 获取对象方法
    #
    # # hasattr(xiaoyu, "adress"):  # 判断对象是否有对应的属性及方法,返回True或False
    #
    # delattr(xiaoyu, "name")  # 删除指定的属性
    #
    # setattr(xiaoyu, "name", "winnie")  # 修改属性的值
    # setattr(xiaoyu, "test1", a)  # 修改方法

import requests